

/*
 * @Descripttion: your project
 * @version: 1.0
 * @Author: hongweixun
 * @Date: 2023-05-17 14:46:34
 * @LastEditors: liyin 2179253556@qq.com
 * @LastEditTime: 2025-09-23 11:23:26
 */
import _ from 'lodash'
export default {
  getYear() {
    const dt = new Date()
    const now = dt.getFullYear()
    return ('2009' + '-' + now)
  },
  // 搜索框防抖函数
  debounce(cb: any, delay: any) {
    let timer: any = null
    return function (this: unknown, ...args: any) {
      if (timer) {
        clearTimeout(timer)
      }
      timer = setTimeout(() => {
        cb.call(this, ...args)
      }, delay)
    }
  },
  // 获取当前系统时间
  getSystemTime(times: any) {
    // const timeTemp = times.split('.')
    const nowTime = Number(times)
    return nowTime
  },
  // 时间戳转换为年月日 星期
  // times 为传入的时间戳
  // num 未传入的类型，1返回年月日 星期， 2返回时分
  changeDate(times: any, num: Number) {
    // 检查是否为10位时间戳，如果是则转换为13位毫秒级时间戳
    let date:any = new Date(times * 1000)
    let Y = date.getFullYear()
    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1)
    let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate())
    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours())
    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes())
    let weeks = date.getDay()
    let fontWeeks = ''
    switch (weeks) {
      case 0:
        fontWeeks = '星期日';
        break;
      case 1:
        fontWeeks = '星期一';
        break;
      case 2:
        fontWeeks = '星期二';
        break;
      case 3:
        fontWeeks = '星期三';
        break;
      case 4:
        fontWeeks = '星期四';
        break;
      case 5:
        fontWeeks = '星期五';
        break;
      case 6:
        fontWeeks = '星期六';
        break;
    }
    if(num === 1){
      return Y + '年' + M + '月' + D + '日  ' + fontWeeks
    } else {
      return h + ':' + m
    }
  },
  // 根据传递进来的数组，与条件，进行数组排序。默认为正序，如需倒序，加入-
  sortListByItem(list: any, row: any) {
    const str = _.sortBy(list,(item:any) => {
      return -Number(item[row])
    })
    return str
  },
  fontSize(res: any) {
    var nowClientWidth = document.documentElement.clientWidth
    return res * (nowClientWidth / 1920)
  },
  // 控制生成的首位不为0的随机数
  generateNonZeroRandomNumber(numDigits:any) {
    let number
    do {
        number = Math.floor(
            Math.pow(10, numDigits - 1) +
            Math.random() * 9 * Math.pow(10, numDigits - 1)
        )
    } while (number % 10 === 0 && number !== 0)
    return number
},
sortObjectByKeys(obj:any) {
  var sortedKeys = Object.keys(obj).sort()
  var sortedObj:any = {}
  sortedKeys.forEach((key) => {
      sortedObj[key] = obj[key]
  })
  return sortedObj
}
}